﻿//-----------------------------------------------------------------------
// <copyright file="FilterWriteSettingsCommand.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.UI.Windows.PrivateMessages
{
    using ChatBox.DomainObjects.Settings;
    using ChatBox.Interfaces;
    using ChatBox.UI.Commands;

    /// <summary>
    /// command to generate a filter from the data on the filter view model
    /// </summary>
    public class FilterWriteSettingsCommand : GenericCommandBase<FilterViewModel>
    {
        /// <summary>
        /// the source of settings data
        /// </summary>
        private readonly IUISettingsRepository uiSettingsRepository;

        /// <summary>
        /// Initializes a new instance of the FilterWriteSettingsCommand class
        /// </summary>
        /// <param name="uiSettingsRepository">the source of settings data</param>
        public FilterWriteSettingsCommand(IUISettingsRepository uiSettingsRepository)
        {
            this.uiSettingsRepository = uiSettingsRepository;
        }

        /// <summary>
        /// Generate the filter
        /// </summary>
        /// <param name="value">the view model</param>
        public override void ExecuteOnValue(FilterViewModel value)
        {
            UISettingsData uiSettings = this.uiSettingsRepository.ReadSettings();

            uiSettings.MaxPrivateMessagesShown = value.MessageCount;

            this.uiSettingsRepository.SaveSettings(uiSettings);
        }
    }
}
